package net.office.service.impl;


import net.office.bean.AnchorInfo;
import net.office.bean.AnchorInfoExample;
import net.office.mapper.AnchorInfoMapper;
import net.office.service.AnchorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnchorInfoServiceImpl implements AnchorInfoService {

    @Autowired
    private AnchorInfoMapper anchorInfoMapper;

    @Override
    public List<AnchorInfo> findAll() {
        AnchorInfoExample example = new AnchorInfoExample();
        return anchorInfoMapper.selectByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer anchorInfoId) {
        return anchorInfoMapper.deleteByPrimaryKey(anchorInfoId);
    }

    @Override
    public List<AnchorInfo> findByAnchorInfo(AnchorInfo anchorInfo) {
        AnchorInfoExample example = new AnchorInfoExample();
        AnchorInfoExample.Criteria criteria = example.createCriteria();

        if(anchorInfo.getAnchorNo() != null
                && anchorInfo.getAnchorNo().trim().length() != 0){
            criteria.andAnchorNoLike("%" + anchorInfo.getStaffNo() + "%");
        }
        if(anchorInfo.getAnchorName() != null
                && anchorInfo.getAnchorName().trim().length() != 0){
            criteria.andAnchorNameLike("%" + anchorInfo.getAnchorName() + "%");
        }
        if(anchorInfo.getAnchorPassword() != null
                && anchorInfo.getAnchorPassword().trim().length() != 0){
            criteria.andAnchorPasswordLike("%" + anchorInfo.getAnchorPassword() + "%");
        }
        if(anchorInfo.getAnchorSex() != null){
            criteria.andAnchorSexEqualTo(anchorInfo.getAnchorSex());
        }
        if(anchorInfo.getAnchorBirthday() != null){
            criteria.andAnchorBirthdayEqualTo(anchorInfo.getAnchorBirthday());
        }
        if(anchorInfo.getAnchorIdCard() != null
                && anchorInfo.getAnchorIdCard().trim().length() != 0){
            criteria.andAnchorIdCardLike("%" + anchorInfo.getAnchorIdCard() + "%");
        }
        if(anchorInfo.getAnchorType() != null){
            criteria.andAnchorTypeEqualTo(anchorInfo.getAnchorType());
        }
        if(anchorInfo.getAnchorLevel() != null){
            criteria.andAnchorLevelEqualTo(anchorInfo.getAnchorLevel());
        }
        if(anchorInfo.getAnchorStatus() != null){
            criteria.andAnchorStatusEqualTo(anchorInfo.getAnchorStatus());
        }
        if(anchorInfo.getStaffId() != null){
            criteria.andStaffIdEqualTo(anchorInfo.getStaffId());
        }
        if(anchorInfo.getStaffNo() != null
                && anchorInfo.getStaffNo().trim().length() != 0){
            criteria.andStaffNoLike("%" + anchorInfo.getStaffNo() + "%");
        }
        if(anchorInfo.getStaffName() != null
                && anchorInfo.getStaffName().trim().length() != 0){
            criteria.andStaffNameLike("%" + anchorInfo.getStaffName() + "%");
        }
        example.or(criteria);

        return anchorInfoMapper.selectByExample(example);
    }

    @Override
    public int insert(AnchorInfo anchorInfo) {
        return anchorInfoMapper.insertSelective(anchorInfo);
    }

    @Override
    public AnchorInfo findOneByAnchorInfoId(Integer anchorInfoId) {
        return anchorInfoMapper.selectByPrimaryKey(anchorInfoId);
    }

    @Override
    public int updateByPrimaryKey(AnchorInfo anchorInfo) {
        return anchorInfoMapper.updateByPrimaryKey(anchorInfo);
    }

    @Override
    public List<AnchorInfo> findAllByStaffId(int staffId) {
        AnchorInfoExample example = new AnchorInfoExample();
        example.createCriteria().andStaffIdEqualTo(staffId);

        return anchorInfoMapper.selectByExample(example);
    }
}
